<?php	
							 					
namespace co2_OS\apps\market\dev\v0_0_0;

use co2_OS as kernel;
use co2_OS\apps\yaml\dev\v0_0_0 as yaml;

class view

{
  protected
    $list=array()
    ;

  public function __construct()
  
  {
    $pkgs=kernel\aptitude::get();
    
    foreach($pkgs as $p)
    
    {
      switch((int)$p->type)
      
      {
        case kernel\aptitude::TYPE_APP:
        
          $type='app';
        
        break;
        
        case kernel\aptitude::TYPE_LIB:
        
          $type='lib';
        
        break;
        
        case kernel\aptitude::TYPE_API:
        
          $type='api';
        
        break;
      }
      
      $this->list[]=(object)array
      (
        'id'      =>  (int)$p->id,
        'name'    =>  $p->pkg,
        'type'    =>  (object)array
          (
            'int'     =>  $p->type,
            'string'  =>  $type
          ),
        'version' =>  $p->version,
        'channel' =>  $p->channel
      );
    }
  }
  
  public function
  __toString
  ()
  
  {
    $list='
+~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~+~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~+
| ID     | Name                    | Type   | Version        | Channel        |
+~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~+~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~+
+~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~+~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~+';

    foreach($this->list as $l)
    
    {
      $id=(string)$l->id;
      
      $_id=strlen($id)+2;
      
      for($id_=$id,$i=$_id;$i<8;$i++)
      $id_.=' ';
      
      // ---
      
      $name=$l->name;
      
      $_name=strlen($name)+2;
      
      for($name_=$name,$i=$_name;$i<25;$i++)
      $name_.=' ';
      
      // ---
      
      $type=$l->type->string;
      
      $_type=strlen($type)+2;
      
      for($type_=$type,$i=$_type;$i<8;$i++)
      $type_.=' ';
      
      // ---
      
      $version=$l->version;
      
      $_version=strlen($version)+2;
      
      for($version_=$version,$i=$_version;$i<16;$i++)
      $version_.=' ';
      
      // ---
      
      $channel=$l->channel;
      
      $_channel=strlen($channel)+2;
      
      for($channel_=$channel,$i=$_channel;$i<16;$i++)
      $channel_.=' ';
      
      // ---
      
      $list.='
| '.$id_.' + '.$name_.' + '.$type_.' + '.$version_.' + '.$channel_.' |
|--------+-------------------------+--------+----------------+----------------|';

    }
    
    $list.='
|________+_________________________+________+________________+________________|
';

    return $list;
  }
}
